package com.nervenets;

import com.nervenets.utils.JodaUtils;
import com.nervenets.utils.PropertiesLoader;
import com.nervenets.web.entity.Menu;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by joe on 17-3-16.
 */
@SuppressWarnings("ALL")
public final class Global {
    public static String profile = "";
    public static String redis_prefix_format = "_KNOWLEDGE_%s";

    public static final class RegExp {
        public static final String MOBILE = "^0{0,1}(13[0-9]|15[0-9]|17[0-9]|18[0-9]|19[0-9])[0-9]{8}$";
    }

    public static final class Constants {
        public static final String REDIS_USER_WEALTH_LOCK = "wealth(%s)";
        public static final String TAGS_KEY = "tags";
        public static final String MOBILE_VALIDATION_CODE = "mvc(%s)";
        public static final String SERVICE_TIME_COUNT_KEY = "stck(%s-%s)";
        public static final String SESSION_USER_PERMISSION = "session-user-permission";
        public static final Object SESSION_USER_INFO = "session-user-info";

        public static String getServiceTimeCountKey(int time, long serviceTimeId) {
            return String.format(SERVICE_TIME_COUNT_KEY, time, serviceTimeId);
        }
    }

    public static final class OrderNumber {
        public static final String NS = "NS";
        public static final String TR = "TR";

        public static String getNormalService(long orderId, int createTime) {
            return NS + createTime + "" + orderId;
        }

        public static String getTransfer(long flowId, int createTime) {
            return TR + createTime + "" + flowId;
        }
    }

    public static PropertiesLoader getApplicationProperties() {
        return new PropertiesLoader(String.format("application%s.properties", profile));
    }

    public static final class WATemplateId {
        public static final String order_success = "IWPfkJgPdefXIKh6aXT81EbPbizvf7lgngxGRSLpji0";
        public static final String order_refuse = "Z85ai2Xh-BGoX8LbILvFqjV9ObtVgtr1mYzRgK_KbtQ";
        public static final String order_cancel = "1phbC0fiHOcgHqLYFDYwyvewJU4dM0vHgWY5RRzApnU";
        public static final String group_buy_failed = "PZYBOzjFqbWBOZhocOKIkiR3hN0dFYGh3R0y9YxtU50";
        public static final String group_buy_success = "n3iVwBfXMwduoPSrMjzf1sSFuuP2FLqPXzVfRJIJ4h4";
        public static final String crowdfunding_failed = "AI86KLgO7Sp-L7GUocPisIcq3-DxxWWQDZONkSnRZrQ";
        public static final String crowdfunding_success = "f-Ggf_C0aQSIKhVXbXw2SHwWy6iU2E_8K-CTjtxyUkU";
    }

    /**
     * 所有的管理员账号权限
     *
     * @return
     */
    public static List<Menu> allAdministratorRoles() {
        List<Menu> menus = new ArrayList<>();
        menus.add(new Menu("用户", "user")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail")
                        .add(new Menu("优惠券", "coupon"))
                        .add(new Menu("积分订单", "integral"))
                )
        );
        final Menu promotionMenus = new Menu("活动", "promotion")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail"))
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"));
        final Menu couponMenus = new Menu("优惠券", "coupon")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail"))
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"));
        final Menu productMenus = new Menu("商品", "product")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail"))
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"));
        final Menu storeMenus = new Menu("门店", "store")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail"))
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"));
        final Menu merchantMenus = new Menu("商户", "merchant")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail")
                        .add(storeMenus)
                        .add(productMenus)
                        .add(couponMenus)
                        .add(new Menu("积分订单", "integral"))
                        .add(new Menu("核销订单", "writeOff"))
                        .add(new Menu("钱包账单", "money"))
                        .add(promotionMenus)
                )
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"));
        menus.add(merchantMenus);
        menus.add(new Menu("商圈", "circle")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail")
                        .add(merchantMenus)
                        .add(storeMenus)
                        .add(productMenus)
                        .add(couponMenus)
                        .add(new Menu("积分订单", "integral"))
                        .add(new Menu("核销订单", "writeOff"))
                        .add(new Menu("钱包账单", "money"))
                        .add(promotionMenus)
                )
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"))
        );
        menus.add(new Menu("机构", "organization")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail")
                        .add(new Menu("核销订单", "writeOff"))
                        .add(new Menu("钱包账单", "money"))
                        .add(promotionMenus)
                )
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"))
        );
        menus.add(new Menu("门店审核", "storeCheck").add(new Menu("列表", "list", true)));
        menus.add(new Menu("商品审核", "productCheck").add(new Menu("列表", "list", true)));
        menus.add(new Menu("优惠券审核", "couponCheck").add(new Menu("列表", "list", true)));
        menus.add(new Menu("活动审核", "promotionCheck").add(new Menu("列表", "list", true)));
        menus.add(new Menu("券购买订单", "couponBuyOrder").add(new Menu("列表", "list", true)));
        menus.add(new Menu("券核销订单", "couponWriteOffOrder").add(new Menu("列表", "list", true)));
        menus.add(new Menu("券转赠订单", "couponTransferOrder").add(new Menu("列表", "list", true)));
        menus.add(new Menu("积分购买订单", "integralBuyOrder").add(new Menu("列表", "list", true)));
        menus.add(new Menu("充值订单", "rechargeOrder").add(new Menu("列表", "list", true)));
        menus.add(new Menu("提现订单", "withdrawOrder").add(new Menu("列表", "list", true)));
        menus.add(new Menu("系统设置", "systemSetting").add(new Menu("列表", "list", true)));

        return menus;
    }

    /**
     * 所有的客户账号权限
     *
     * @return
     */
    public static List<Menu> allCustomerRoles() {
        List<Menu> menus = new ArrayList<>();

        final Menu promotionMenus = new Menu("活动", "promotion")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail"))
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"));
        final Menu payPromotionMenus = new Menu("支付优惠活动", "payPromotion")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail"))
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"));
        final Menu couponMenus = new Menu("优惠券", "coupon")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail"))
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"));
        final Menu productMenus = new Menu("商品", "product")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail"))
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"));
        final Menu storeMenus = new Menu("门店", "store")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail"))
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"));
        final Menu merchantMenus = new Menu("商户", "merchant")
                .add(new Menu("列表", "list", true))
                .add(new Menu("搜索", "search"))
                .add(new Menu("详情查看", "detail")
                        .add(storeMenus)
                        .add(productMenus)
                        .add(couponMenus)
                        .add(new Menu("积分订单", "integral"))
                        .add(new Menu("核销订单", "writeOff"))
                        .add(new Menu("钱包账单", "money"))
                        .add(promotionMenus)
                )
                .add(new Menu("删除", "delete"))
                .add(new Menu("添加", "add"));
        menus.add(couponMenus);
        menus.add(merchantMenus);
        menus.add(storeMenus);
        menus.add(productMenus);
        menus.add(promotionMenus);
        menus.add(payPromotionMenus);
        menus.add(new Menu("优惠券核销", "couponWriteOff").add(new Menu("列表", "list", true)));
        menus.add(new Menu("积分购买订单", "integralBuyOrder").add(new Menu("列表", "list", true)));
        menus.add(new Menu("充值订单", "rechargeOrder").add(new Menu("列表", "list", true)));
        menus.add(new Menu("提现订单", "withdrawOrder").add(new Menu("列表", "list", true)));
        menus.add(new Menu("活动退款", "promotionRefund").add(new Menu("列表", "list", true)));
        menus.add(new Menu("收支明细", "wealthFlows").add(new Menu("列表", "list", true)));
        menus.add(new Menu("数据分析", "dataAnalysis").add(new Menu("列表", "list", true)));

        menus.add(new Menu("商户设置", "accountSetting")
                .add(new Menu("修改密码", "resetPassword"))
                .add(new Menu("提现账号管理", "withdraw")
                        .add(new Menu("提现账号列表", "list", true))
                        .add(new Menu("管理提现账号", "manager"))
                        .add(new Menu("添加提现账号", "add"))
                )
        );
        return menus;
    }
}
